package com.tangqihang229350526.mynote

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.tangqihang229350526.mynote.databinding.FragmentMineBinding
import com.tangqihang229350526.mynote.repository.UserRepository
import com.tangqihang229350526.mynote.viewmodel.MineViewModel

class MineFragment : Fragment() {
    private var binding: FragmentMineBinding? = null
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?, savedInstanceState: Bundle?
    ): View {
        val mineViewModel = ViewModelProvider(this)[MineViewModel::class.java]
        binding = FragmentMineBinding.inflate(inflater, container, false)
        val root: View = binding!!.root
        mineViewModel.getName().observe(this) { s -> binding!!.tvName.text = "欢迎你 $s" }
        UserRepository.instance?.let { mineViewModel.setUser(it.userData) }
        return root
    }

    override fun onDestroyView() {
        super.onDestroyView()
        binding = null
    }
}